import * as ACTIONS from '../../actions/examination-analysis/recommendationAction';
import { ENUM_VIEW } from '../../../schema/constants';

/**
 * 数据视图默认状态
 * @type {Object}
 */
export const DEFAULT_DATA_STATE = {
	message: '',
	options: [{
		ID: 201,
		label: '名师推荐'
	}, {
		ID: 202,
		label: '其他老师推荐'
	}, {
		ID: 203,
		label: '热门知识点'
	}, {
		ID: 204,
		label: '核心考点'
	}, {
		ID: 205,
		label: '精选专题'
	}, {
		ID: 206,
		label: '名校试卷'
	}, {
		ID: 207,
		label: '精品试卷'
	}, {
		ID: 0,
		label: '出题来源分布'
	}],
	// 名师推荐
	optTeacherRecommendedData: {
		isFetching: false,
		data: {}
	},
	// 其他老师推荐
	optOtherTeacherRecommendedData: {
		isFetching: false,
		data: {}
	},
	// 热门知识点
	optPopularKnowledgeData: {
		isFetching: false,
		data: {}
	},
	// 核心考点
	optCoreTestSiteData: {
		isFetching: false,
		data: {}
	},
	// 精选专题
	optFeaturedtopicData: {
		isFetching: false,
		data: {}
	},
	// 名校试卷
	optSchoolPaperData: {
		isFetching: false,
		data: {}
	},
	// 精品试卷
	optCollectiblePaperData: {
		isFetching: false,
		data: {}
	},
	// 出题来源分布
	optSourceDistributionData: {
		isFetching: false,
		data: {}
	}
};


export function recommendationReducer(state = DEFAULT_DATA_STATE, action = {}) {
	let { type, payload } = action;

	switch(type) {
		case ACTIONS.GET_DATA_REQUEST: 
		{
			let { key } = payload;
			return Object.assign({}, state, {
				[key]: {
					isFetching: true,
					data: {}
				}
			});
		}
		case ACTIONS.GET_DATA_SUCCESS: 
		{
			console.log(payload);
			let { key, data } = payload;
			return Object.assign({}, state, {
				[key]: {
					isFetching: false,
					data
				}
			})
		}
		case ACTIONS.GET_DATA_FAILURE:
		{
			let { key, message } = payload;
			return Object.assign({}, state, {
				message,
				[key]: {
					isFetching: false,
					data: {}
				}
			})
		}
		default: 
			return state;
	}
};